package com.controller;

import com.pojo.Products;
import com.pojo.Result;
import com.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/products")
public class ProductsController {

    @Autowired
    private ProductsService productsService;

    @PostMapping
    public Result<Void> createProduct(@RequestBody Products product) {
        return productsService.createProduct(product);
    }

    @PutMapping("/{id}")
    public Result<Void> updateProduct(@PathVariable Integer id, @RequestBody Products product) {
        product.setId(id);
        return productsService.updateProduct(product);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteProduct(@PathVariable Integer id) {
        return productsService.deleteProduct(id);
    }

    @GetMapping("/{id}")
    public Result<Products> getProductById(@PathVariable Integer id) {
        return productsService.getProductById(id);
    }

    @GetMapping
    public Result<List<Products>> getAllProducts() {
        return productsService.getAllProducts();
    }

    @GetMapping("/available")
    public Result<List<Products>> getAvailableProducts() {
        return productsService.getAvailableProducts();
    }


}